package com.kede.api.order.controller;

import com.kede.api.order.controller.po.CreateLeeScorePo;
import com.kede.api.order.service.ILessScoreOrderService;
import com.kede.domain.LeescoreGoodsDomain;
import com.kede.ienum.PayTypeEnum;
import com.kede.ienum.SourceChannelEnum;
import com.kede.pojo.ResHttp;
import com.kede.service.LeescoreGoodsService;
import com.kede.service.LeescoreOrderGoodsService;
import com.kede.utils.ValidList;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 订单服务
 *
 * @author 11856
 * @date 2023/06/12
 */
@Slf4j
@RestController
@RequestMapping("order")
public class OrderController {

    @Resource
    private ILessScoreOrderService lessScoreOrderService;

    @Resource
    private LeescoreOrderGoodsService orderGoodsService;

    /**
     * 创建德币订单
     *
     * @Author: Pr.li
     * @Date: 2023/5/22 11:12
     * @Param: [com.kede.api.order.controller.po.CreateLeeScorePo]
     * @Return: com.kede.pojo.ResHttp
     ***/
    @PostMapping("createLeeScoreOrder")
    public ResHttp createLeeScoreOrder(@RequestBody @Validated CreateLeeScorePo leeScorePo){
        return lessScoreOrderService.createLeeScoreOrder(leeScorePo);
    }


    /**
     * 德币订单确认收货
     *
     * @Author: Pr.li
     * @Date: 2023/5/22 11:13
     * @Param: [java.lang.Integer, java.lang.Integer]
     * @Return: com.kede.pojo.ResHttp
     ***/
    @GetMapping("receiveOrder")
    public ResHttp receiveOrder(Integer orderId,Integer userId){
        return lessScoreOrderService.receiveOrder(orderId,userId);
    }

    /**
     * 德币订单删除
     *
     * @Author: Pr.li
     * @Date: 2023/5/22 11:14
     * @Param: [java.lang.Integer]
     * @Return: com.kede.pojo.ResHttp
     ***/
    @GetMapping("deleteOrder")
    public ResHttp deleteOrder(Integer orderId){
        try {
            lessScoreOrderService.deleteOrder(orderId);
            return ResHttp.ok();
        }catch (Exception e){
            return ResHttp.failMsg(e.getMessage());
        }
    }

    /**
     * 释放某一个德币订单库存
     * @param orderId
     * @return
     */
    @GetMapping("backOneOrderById")
    public ResHttp backOneOrderById(Integer orderId){
        try {
            lessScoreOrderService.backOneOrderById(orderId);
            return ResHttp.ok();
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
            return ResHttp.fail();
        }
    }




}
